import axios from '../AxiosConfig.js'

export const bindingExchangeQueue = (data) => {
  return axios({
    method: 'post',
    url: '/api/bindings/' + encodeURIComponent(data.vhost) + "/e/" + data.source + "/q/" + data.destination,
    data: {
      "vhost": data.vhost,
      "source": data.source,
      "destination_type": "q",
      "destination": data.destination,
      "routing_key": data.routing_key,
      "arguments": {},
    }
  })
}

export const unBindingExchangeQueue = (data) => {
  let routing_key = (data.routing_key === undefined || data.routing_key === "") ? "~" : data.routing_key;
  return axios({
    method: 'delete',
    url: '/api/bindings/' + encodeURIComponent(data.vhost) + "/e/" + data.source + "/q/" + data.destination + "/" + routing_key,
    data: {
      "properties_key": routing_key
    }
  })
}

export const listBinding = () => {
  return axios({
    method: 'get',
    url: '/api/bindings'
  })
}

export const listBindingByVhost = (vhost) => {
  return axios({
    method: 'get',
    url: '/api/bindings/' + encodeURIComponent(vhost)
  })
}

export const closeConnection = data => {
  return axios({
    method: 'delete',
    url: '/api/connections/' + encodeURIComponent(data.vhost) +'/' + data.name,
  })
}


